// 首次安装插件时执行一次，后面不会重新执行
chrome.runtime.onInstalled.addListener((msg, sender) => {
  // console.log(msg)
  // console.log(sender)
  // if ((msg.from === 'content') && (msg.subject === 'showPageAction')) {
  //   // Enable the page-action for the requesting tab.
  //   chrome.pageAction.show(sender.tab.id);
  // }
})

chrome.runtime.onMessage.addListener((msg, sender, response) => {
  // console.log(msg)
})

// 监听tab页面加载状态，添加处理事件
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
  if (changeInfo.status === 'complete' && /^https/.test(tab.url)) {
    chrome.scripting.executeScript({
      target: { tabId: tabId },
      files: ['./content.js']
    }).then(() => {
      console.log('injected script success')
    }).catch((err) => {
      console.log(err)
    })
    console.log('Run')
  }
})